package br.com.webcrm.service.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.webcrm.dao.EnderecoDAO;
import br.com.webcrm.model.Endereco;
import br.com.webcrm.service.EnderecoService;


@Service(value = "enderecoService")
public class EnderecoServiceImpl extends BaseServiceImpl implements EnderecoService, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5637434279342693290L;
	
	@Resource
	private EnderecoDAO enderecoDAO;

	public EnderecoDAO getEnderecoDAO() {
		return enderecoDAO;
	}

	public void setEnderecoDAO(EnderecoDAO enderecoDAO) {
		this.enderecoDAO = enderecoDAO;
	}

	@Override
	public Endereco persistir(Endereco endereco) throws Exception {
		if (endereco.getIdEndereco() == null){
			return this.gravar(endereco);
		}else{
			return this.alterar(endereco);
		}
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public Endereco gravar(Endereco endereco) throws Exception {
		return getEnderecoDAO().gravar(endereco);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public Endereco alterar(Endereco endereco) throws Exception {
		return getEnderecoDAO().atualizar(endereco);
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public List<Endereco> consultarTodos() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public void excluir(Endereco endereco) throws Exception {
		getEnderecoDAO().excluir(endereco);
		
	}

	@Override
	@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
	public List<Endereco> consultarPorIdEntidade(Integer idEntidade)
			throws Exception {
		return getEnderecoDAO().consultarPorIdEntidade(idEntidade);
	}
	
	

}
